package com.zhiyou100.action;

import com.zhiyou100.exception.MyException;
import com.zhiyou100.service.Test05Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author yang
 * @className Test05
 * @packageName com.zhiyou100.action
 * @Description TODO action + service
 * @date 2020-08-25 14:24
 */

@Controller
@RequestMapping("/test05")
public class Test05 {

    private Test05Service service;

    @Autowired
    public void setService(Test05Service service) {
        this.service = service;
    }

    @RequestMapping("/login.action")
    public String loginMethod(String sname, String spwd, HttpSession session) {
        if (!service.judgeTheName(sname)) {
            // 名字是否存在
            throw new MyException("账号不存在！！！");

        }
        if (!service.judgeTheNameAndPwd(sname, spwd)) {
            throw new MyException("密码错误");
        }
        session.setAttribute("sname", sname);
        return "test05_exception/success";
    }
}
